<template>
	<view class="package page bgf6">
		<view class="bgff py8 px15" @click="showShop">
			<text>{{selectShop.name}}</text>
			<image class="ml4 w12" src="/static/img/icon/down.png" mode="widthFix"></image>
		</view>
		<scroll-view scroll-y="true" class="list bgf6">
			<view v-for="(item,index) in list" class="bgff p8 mx12 my16"  @click="edit(item)">
				<view class="fs18 bold6 px14 py10">{{item.name}}</view>
				<view class="flex flexC flexW mt5 aliC" >
					<text v-for="(t,idx) in item.set" :key="idx" class="bged r40 bor41 w150 py6 mx12 mb12">{{t.hour}}小时 {{t.amount}}元</text>
				</view>
			</view>
		</scroll-view>

		<!-- 店铺选择 -->
		<uni-popup ref="shopPicker" type="bottom">
			<shop-list @search="search" :list="shopList" @onSelectShop="onSelectShop" @close="onClose"></shop-list>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				selectShop: null,
				shopList: [],
				list:[]

			}
		},
		onLoad(option) {
			var select = option.selectShop;
			if (select != null) {
				this.selectShop = JSON.parse(select);
			}
			this.getShopList();
			this.getList();
		},
		methods: {
			
			edit(item){
				console.info("=====edit====="+JSON.stringify(item));
			   uni.navigateTo({
			   	url:'../package/edit?id='+item.id
			   })
			},

			getList() {

				let param = {
					shop_id:this.selectShop.id
				};
				let that = this;
				this.$api.roomSetList(param).then(res => {

					console.info(JSON.stringify(res));
					if (res.code == 1) {
						that.list = res.data;
					} else {

					}
				})
			},
			onClose() {
				this.$refs.shopPicker.close();
			},
			getShopList() {
				let param = {
					keyword: this.keyword
				};
				let that = this;
				this.$api.getShopList(param).then(res => {

					console.info(JSON.stringify(res));
					if (res.code == 1) {
						that.shopList = res.data;
						if (that.shopList.length > 0) {

						}
					} else {

					}
				})
			},

			showShop() {
				this.$refs.shopPicker.open();

			},
			search(value) {

				this.keyword = value;
				this.getShopList();
			},

			onSelectShop(item) {
				this.selectShop = item;
				this.$refs.shopPicker.close();
				this.page = 1;
				this.list = [];

				this.getList();
			},
		}
	}
</script>

<style lang="scss" scoped>
	.package {
		.w12 {
			width: 24rpx;
			height: 24rpx;
		}

		.w150 {
			width: calc(50% - 52rpx);
		}

		.list {
			height: calc(100vh - 72rpx);
		}
	}
</style>
